import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class AddRoomTextField extends StatelessWidget {
  final String title;
  final String? unit;
  final String? value;
  final TextEditingController controller;
  final Function callback;
  final bool digitsOnly;

  const AddRoomTextField(
      {super.key,
      required this.title,
      required this.callback,
      this.unit,
      this.value,
      required this.controller,
      required this.digitsOnly});

  @override
  Widget build(BuildContext context) {
    if (value != null) {
      // controller = TextEditingController(text: value);
      controller.text = value!;
    }

    return Card(
      margin: EdgeInsets.only(left: 10.w, right: 10.w, top: 25.h),
      color: Colors.white70,
      child: Container(
        padding: EdgeInsets.only(left: 10.w, bottom: 10.h),
        child: TextField(
          keyboardType: digitsOnly
              ? const TextInputType.numberWithOptions(
                  decimal: true, signed: true)
              : null,
          inputFormatters: digitsOnly
              ? [
                  FilteringTextInputFormatter.allow(
                      RegExp(r'^\d*\.?\d*|-?\d*\.?\d*')),
                ]
              : null,
          controller: controller,
          onChanged: (value) {
            callback(value);
          },
          decoration: InputDecoration(
            labelText: title,
            labelStyle: TextStyle(color: Colors.black, fontSize: 40.sp),
            // floatingLabelStyle: const TextStyle(color: Color(0xff45C7B8)),
            floatingLabelStyle: const TextStyle(color: Colors.blue),
            suffixText: unit,
          ),
          style: TextStyle(fontSize: 30.sp),
        ),
      ),
    );
  }
}
